#include "arvbin.h"
#include "binheapMin.h"


arvbin :: arvbin( no &valor)
{
	 val = valor;
	 esq = NULL;
	 dir = NULL;
 
}


arvbin :: arvbin( no &valor, arvbin *arvbin_esq, arvbin *arvbin_dir) 
{

 	val = valor;
    esq = arvbin_esq;
    dir = arvbin_dir;    
    
}
    

arvbin:: ~arvbin()
{
    if ( dir != NULL ) 
       delete dir;
    if ( esq != NULL ) 
       delete esq;
    
}
    
void arvbin:: mostra() const
{
	cout << "(" << val.simbolo << " " << val.frequencia;
      if (esq != NULL)
         esq->mostra();
      if (dir != NULL)
        dir->mostra();
    cout << ")";
}

void arvbin::mostraCodigo(int n, int *vet, arvbin *arv) const
{
    if ((arv->esq==NULL) && (arv->dir==NULL)){
        cout << "\nSimbolo: " << arv->val.simbolo << "  Codigo: ";
        for (int i=0; i<n; i++)
            cout << vet[i];
    }
    if (arv->esq!=NULL){
        vet[n] = 0;
        mostraCodigo(n+1,vet,arv->esq);
    }
    if (arv->dir!=NULL){
        vet[n] = 1;
        mostraCodigo(n+1,vet,arv->dir);
    }
}
